import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
let token = sessionStorage.getItem('token')
let userInfo = sessionStorage.getItem('userInfo')
let bill = sessionStorage.getItem('bill')
let menu = sessionStorage.getItem('menu')

export default new Vuex.Store({
  state: {
    addRoutesState: false,
    menu: menu ? JSON.parse(menu) : [],
    token: token ? token : '',
    userInfo: userInfo ? JSON.parse(userInfo) : {},
    bill: bill ? JSON.parse(bill) : {} //存储一个账单数据，给账单详细页使用
  },
  getters: {},
  mutations: {
    modifyRoutesState(state, paylaod) {
      state.addRoutesState = paylaod
    },
    tokenMt(state, paylaod) {
      state.token = paylaod
    },
    userInfo(state, paylaod) {
      state.userInfo = paylaod
    },
    bill(state, paylaod) {
      state.bill = paylaod
    },
    menu(state, payload) {
      state.menu = payload
    }
  },
  actions: {
    routesState({ commit }, paylaod) {
      commit('modifyRoutesState', paylaod)
    },
    token({ commit }, paylaod) {
      commit('tokenMt', paylaod)
    },
    userInfo({ commit }, paylaod) {
      commit('userInfo', paylaod)
    },
    bill({ commit }, paylaod) {
      commit('bill', paylaod)
    },
    menu({ commit }, paylaod) {
      commit('menu', paylaod)
    }
  },
  modules: {}
})
